-- Checks if the MySQL mode is activated or not --
if ( Hyperion.Schema.Configuration[ "MySQL_Mode" ] == true and Hyperion.Schema.Configuration[ "SQLite_Mode" ] == false ) then
	require( "mysqloo" )

	MsgN( "[Hyperion] MySQL Mode Activated" )
elseif ( Hyperion.Schema.Configuration[ "MySQL_Mode" ] == true and Hyperion.Schema.Configuration[ "SQLite_Mode" ] == true ) then
	MsgN( "[Hyperion] SQL Error: You can't use both MySQL and SQLite! Pick one!" )
end

-- Handles the MySQL connection --
function Hyperion.MySQL_Connect()
	if ( Hyperion.Schema.Configuration[ "MySQL_Mode" ] == false ) then
		return
	elseif ( !mysqloo ) then
		MsgN( "[Hyperion] SQL Error: No module detected!" )

		return
	end

	HyperionDB = mysqloo.connect( Hyperion.Schema.Configuration.MySQL_Host, Hyperion.Schema.Configuration.MySQL_Username, Hyperion.Schema.Configuration.MySQL_Password, Hyperion.Schema.Configuration.MySQL_Database );

	HyperionDB.onConnectionFailed = function( db, e )
		MsgN( "[Hyperion] SQL Error: " .. tostring( e ) )
	end

	HyperionDB.onConnected = function()
		MsgN( "[Hyperion] MySQL Connection Established" )
	end

	HyperionDB:connect()
end

-- Checks if the MySQL mode is activated or not, and if it is, connects to the database --
if ( Hyperion.Schema.Configuration[ "MySQL_Mode" ] == true and Hyperion.Schema.Configuration[ "SQLite_Mode" ] == false ) then
	Hyperion.MySQL_Connect()
end

-- Checks the status of the MySQL connection --
function Hyperion.MySQL_Status()
	if ( Hyperion.Schema.Configuration[ "MySQL_Mode" ] == false ) then
		return
	elseif( !HyperionDB ) then
		return
	end

	if ( HyperionDB:status() == 2 ) then
		MsgN( "[Hyperion] SQL Error: Disconnected from database, reconnecting..." )

		Hyperion.MySQL_Connect()
	end
end
timer.Create( "MySQLStatus", 30, 0, Hyperion.MySQL_Status )